package com.sinsz.c.properties;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sinsz.c.properties.support.ApplicationProp;
import com.sinsz.c.properties.support.ProtocolProp;
import com.sinsz.c.properties.support.RegistryProp;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 注入Dubbo配置
 * @author chenjianbo
 * @date 2017/11/23
 */
@ConfigurationProperties(prefix = "dubbo")
public class DubboProperties {

    private boolean check;

    private ApplicationProp application;

    private RegistryProp registry;

    private ProtocolProp protocol;

    public ApplicationProp getApplication() {
        return application;
    }

    public void setApplication(ApplicationProp application) {
        this.application = application;
    }

    public RegistryProp getRegistry() {
        return registry;
    }

    public void setRegistry(RegistryProp registry) {
        this.registry = registry;
    }

    public ProtocolProp getProtocol() {
        return protocol;
    }

    public void setProtocol(ProtocolProp protocol) {
        this.protocol = protocol;
    }

    public boolean isCheck() {
        return check;
    }

    public void setCheck(boolean check) {
        this.check = check;
    }

    @Override
    public String toString() {
        ObjectMapper mapper = new ObjectMapper();
        try {
            return mapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
            e.printStackTrace(System.out);
        }
        return super.toString();
    }
}